In [2]:
# polyconverge.m

N = 500
mu = 0.01
x = zeros(N+1)

x[0] = 3.0

for k in range(0,N-1):
    x[k+1] = (1-2*mu)*x[k]+4*mu
    
plot(x)
Out[2]:
[<matplotlib.lines.Line2D at 0x1077806d0>]

6.15. Try to run with a set of parameters:

  1. mu = [-0.01, 0, 0.0001, 0.02, 0.03, 0.05, 1, 10]. Can mu be too large or too small?
  2. Try N = 5, 40, 100, 5000. Can N be too large?
  3. Try a variety of x[0] values. Can it be too large/small.
In [3]:
def polyconverge(x0, mu, N):
    x = zeros(N+1)

    x[0] = x0

    for k in range(0,N-1):
        x[k+1] = (1-2*mu)*x[k]+4*mu
    
    return x
In [10]:
for mu in  [0.0001, 0.02, 0.03, 0.05]:
    plot(polyconverge(3, mu, 500))
    ylim( (0,10) )

for mu in [-0.01, 0, 1, 10]:
    figure()
    plot(polyconverge(3, mu, 500))
    ylim( (0,10) )
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
<ipython-input-10-b7a8d7b004d2> in <module>()
      5 for mu in [-0.01, 0, 1, 10]:
      6     figure()
----> 7     plot(polyconverge(3, mu, 500))
      8     ylim( (0,10) )

/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/pyplot.pyc in plot(*args, **kwargs)
   2813         ax.hold(hold)
   2814     try:
-> 2815         ret = ax.plot(*args, **kwargs)
   2816         draw_if_interactive()
   2817     finally:

/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/axes.pyc in plot(self, *args, **kwargs)
   3995             lines.append(line)
   3996 
-> 3997         self.autoscale_view(scalex=scalex, scaley=scaley)
   3998         return lines
   3999 

/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/axes.pyc in autoscale_view(self, tight, scalex, scaley)
   1963                 y1 += delta
   1964             if not _tight:
-> 1965                 y0, y1 = ylocator.view_limits(y0, y1)
   1966             self.set_ybound(y0, y1)
   1967 

/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/ticker.pyc in view_limits(self, dmin, dmax)
   1282         dmin, dmax = mtransforms.nonsingular(dmin, dmax, expander = 1e-12,
   1283                                                         tiny=1.e-13)
-> 1284         return np.take(self.bin_boundaries(dmin, dmax), [0,-1])
   1285 
   1286 

/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/ticker.pyc in bin_boundaries(self, vmin, vmax)
   1254                 break
   1255         if self._trim:
-> 1256             extra_bins = int(divmod((best_vmax - vmax), step)[0])
   1257             nbins -= extra_bins
   1258         return (np.arange(nbins+1) * step + best_vmin + offset)

OverflowError: cannot convert float infinity to integer
In [12]:
for x0 in [-10, -5, 0, 1, 2, 3, 5, 10]:
    plot(polyconverge(x0, 0.01, 500))
In [14]:
for N in [5, 40, 100, 500]:
    plot(polyconverge(5, 0.01, N))